from rest_framework import serializers

from areas.models import Area


class AreasSerializer(serializers.ModelSerializer):
    """省序列化器"""
    # id = serializers.HyperlinkedRelatedField(view_name='area-detail', read_only=True)
    url = serializers.HyperlinkedIdentityField(view_name='area-detail', read_only=True)

    class Meta:
        model = Area
        exclude = ('parent', )


class SubSerializer(serializers.ModelSerializer):
    """详情试图使用的序列化器"""
    subs = AreasSerializer(many=True)  # 写在多的一方 要写many=True

    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']

